package com.mystore.manage.controller;

import com.mystore.framework.pojo.User;
import com.mystore.framework.service.impl.IUserServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("author/admin")
public class ManageController {
    @Resource
    private IUserServiceImpl iUserServiceImpl;
    @GetMapping("index.do")
    public String index(Model model){
        return "manage_login";
    }
    @PostMapping("login.do")
    public String login(Model model, @Validated User user, HttpServletRequest request){
        HttpSession session=request.getSession();
        User admin=iUserServiceImpl.adminLogin(user);
        System.out.println(admin);
        if(admin!=null){
            session.setAttribute("userId",admin.getUserId());
            return "manage_index";
        }
        else{
            model.addAttribute("msg","账号或密码错误");
            return "manage_login";
        }
    }
}
